# -*- coding: utf-8-*-
_author_ = 'yykrlc'
import flask_restful
from functools import wraps
import json
from flask import request
import time
import datetime


def auth_token(request_, permission=[]):
    """权限验证修饰器"""
    def decorator(f):
        @wraps(f)
        def decorated_function(*args, **kwargs):
            permission_ = permission or []
            token = request_.args.get('token')
            request_oid = request_.values.get('oid', type=int)
            if not token:
                flask_restful.abort(401, message="token is null")
            admin_role = 0
            if permission_ and admin_role != 1 and admin_role not in permission_:  #
                flask_restful.abort(401, message=u"权限不足", data=json.dumps(dict(admin_role=admin_role, permission=permission_)))
            return f(*args, **kwargs)
        return decorated_function
    return decorator



def str_mktime(times):
    """字符串时间转换时间戳"""
    return time.mktime(time.strptime(times, "%Y-%m-%d %H:%M:%S"))